Total Complexity | 2 |
Total Lines | 18 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
6 | |||
7 | @CommandHandler(CreateContactCommand) |
||
8 | export class CreateContactCommandHandler { |
||
9 | constructor( |
||
10 | @Inject('IContactRepository') |
||
11 | private readonly contactRepository: IContactRepository |
||
12 | ) {} |
||
13 | |||
14 | public async execute(command: CreateContactCommand): Promise<string> { |
||
15 | const { firstName, lastName, company, phoneNumber, email, notes } = command; |
||
16 | |||
17 | if (!firstName && !lastName && !company) { |
||
18 | throw new EmptyContactException(); |
||
19 | } |
||
20 | |||
21 | return ( |
||
22 | await this.contactRepository.save( |
||
23 | new Contact(firstName, lastName, company, email, phoneNumber, notes) |
||
24 | ) |
||
28 |